package srt;


import java.sql.*;

public class users extends Database{
private int  UserID;
private String UserName;
private String UserPassword;
private String strSql;
public users(){
UserID=0;
UserName="";
UserPassword="";
strSql="";
}
public boolean add_user(){
	strSql="insertint ousers(UserName,UserPassword)";
	strSql=strSql+"values(";
	strSql=strSql+"'"+UserName+"',";
	strSql=strSql+"'"+UserPassword+"'";
	strSql=strSql+")";
	
	boolean isAdd=super.exeSql(strSql);
	return isAdd;
}
public boolean is_exist(){
	strSql="select*from'users'whereUserName=UserName";
	ResultSet rs=null;
	boolean isExist=false;
	try{
		rs=super.exeSqlQuery(strSql);
	while(rs.next()){
		isExist=true;
	} 
	}catch(Exception ex) {
		System.out.println(ex.toString ());
	}
	return isExist;
} 
public boolean user_valid(){
	strSql="select*fromuserswhereUserName="+ "'"+UserName+"'"+"andUserPassword="+"'"+UserPassword+"'";
 	ResultSet rs=null;
	boolean isvalid=false;
	try{
		rs=super.exeSqlQuery(strSql);
	while(rs.next()){
		this.UserID=rs.getInt("UserID");
		isvalid=true;
	} 
	}catch(Exception ex) {
		System.out.println(ex.toString ());
	} return isvalid;
 } 
public boolean init(){
	strSql="select*fromuserswhereUserID=";
	strSql=strSql+UserID;
	try{
		ResultSet rs=super.exeSqlQuery(strSql);
		if(rs.next()){ this.UserID=rs.getInt ("UserID");
		 this.UserName=rs.getString ("UserName");
		 this.UserPassword=rs.getString ("UserPassword");
		return true;
		}else{
			return false;
		}
	}catch(Exception ex){ 
		System.out.println(ex.toString ());
		return false;
	}
}
public ResultSet show_all_users(){
	strSql="select*fromusers";
	ResultSet rs=null;
	try{ 
		rs=super.exeSqlQuery(strSql);
	}catch(Exception ex){ 
		System.out.println(ex.toString ());
	} return rs;
}
public int getUserID(){ 
	return UserID;
} 
public void setUserID(int userID){
	UserID=userID;
} 
public String getUserName(){ 
	return UserName;
} 
public void setUserName(String userName){ 
	UserName=userName;
}
public String getUserPassword(){ 
	return UserPassword;
}
public void setUserPassword(String userPassword){
	UserPassword=userPassword;
}
}